<?php
class LogConnect extends AppModel
{
    public $name = 'LogConnect';
    public $primaryKey = '_id';

    public function get_play_time_avg($_db_name)
    {
        $this->useDbConfig = $_db_name['log'];

        $data = $this->find('all');

        $play_time = 0;
        foreach($data as $value)
        {
            $play_time += $value['LogConnect']['play_time'];
        }

        return $play_time;
    }

    public function get_log($_db_name)
    {
        $this->useDbConfig = $_db_name['log'];
        return $this->find('all');
    }

    public function get_connect_log($_db_name, $_usn)
    {
        $this->useDbConfig = $_db_name['log'];
        $params = array(
            'conditions' => array(
                'usn' => $_usn
            ),
        );
        $data = $this->find('first', $params);

        return $data;
    }

    public function char_del($_db_name, $_usn, $_char_id)
    {
        $this->useDbConfig = $_db_name['log'];

        $params = array('usn' => $_usn);
        if( !$this->deleteall($params) )
            return false;

        return true;
    }

    public function delect_all($_db_name)
    {
        $this->useDbConfig = $_db_name['log'];
        $this->deleteAll(array('_id not' => null));
        return true;
    }

}